import request from '@/utils/request'
import qs from 'qs'

// 查询角色列表
export function listRole(data) {
  return request({
    url: '/system/role/list',
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  })
}

// 查询角色详细
export function getRole(roleId) {
  return request({
    url: '/system/role/' + roleId,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    method: 'get'
  })
}

// 新增角色
export function addRole(data) {
  return request({
    url: '/system/role/add',
    method: 'post',
    data: data
  })
}

// 修改角色
export function updateRole(data) {
  return request({
    url: '/system/role/edit',
    method: 'post',
    data: data
  })
}

// 角色数据权限
export function dataScope(data) {
  return request({
    url: '/system/role/dataScope',
    method: 'put',
    data: data
  })
}

// 角色状态修改
export function changeRoleStatus(roleId, status) {
  const data = {
    roleId,
    status
  }
  return request({
    url: '/system/role/changeStatus',
    method: 'POST',
    data: data
  })
}

// 删除角色
export function delRole(roleId) {
  return request({
    url: '/system/role/' + roleId,
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    method: 'POST'
  })
}

// 导出角色
export function exportRole(data) {
  return request({
    url: '/system/role/export',
    responseType: 'blob',
    method: 'post',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    data: qs.stringify(data)
  })
}

// 查询角色已授权用户列表
export function allocatedUserList(query) {
  return request({
    url: '/system/role/authUser/allocatedList',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    method: 'get',
    params: query
  })
}

// 查询角色未授权用户列表
export function unallocatedUserList(query) {
  return request({
    url: '/system/role/authUser/unallocatedList',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    method: 'GET',
    params: query
  })
}

// 取消授权用户 或者多个
export function authUserCancel(data) {
  return request({
    url: '/system/role/authUser/remove',
    method: 'POST',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    params: data
  })
}

// 批量取消授权用户  用 authUserCancel 
// export function authUserCancelAll(data) {
//   return request({
//     url: '/system/role/authUser/cancelAll',
//     headers: { 'content-type': 'application/x-www-form-urlencoded' },
//     method: 'POST',
//     params: qs.stringify(data)
//   })
// }

// 批量选择用户授权
export function authUserSelectAll(data) {
  return request({
    url: '/system/role/authUser/empower',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    method: 'POST',
    params: data
  })
}

// 08、获取角色选择框列表
export function roleOptionSelect() {
  return request({
    url: '/system/role/optionselect',
    method: 'get',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
  })
}





